package com.jetpackframework.rxjetpack.observable;

import com.jetpackframework.rxjetpack.DisposableHelper;
import com.jetpackframework.rxjetpack.Dispose;
import com.jetpackframework.rxjetpack.DisposeImpl;
import com.jetpackframework.rxjetpack.Observable;
import com.jetpackframework.rxjetpack.Observer;

public class ObservableJust<T> extends Observable<T> {
    private T t;

    public ObservableJust(T t) {
        this.t = t;
    }

    @Override
    public void subscribeActual(Observer<? super T> observer) {
        ScalarDisposable disposable = new ScalarDisposable<T>(observer,t);
        disposable.run();
    }

    static final class ScalarDisposable<T> extends BaseObserver<T>{
        private Observer<? super T> observer;

        public ScalarDisposable(Observer<? super T> observer, T t) {
            super(t);
            this.observer = observer;
        }

        @Override
        public void onNext(T o) throws Exception {
            observer.onNext(o);
        }

        @Override
        public void onError(Throwable t) {
            observer.onError(t);
        }

        @Override
        public void onComplete() {
            observer.onComplete();
        }
    }
}
